package com.liveinstars.activity.business.activity.service.impl;

import com.baidu.unbiz.easymapper.MapperFactory;
import com.liveinstars.activity.business.activity.repository.po.Activity;
import com.liveinstars.activity.business.activity.entity.ActivityDO;
import com.liveinstars.api.dto.ActivityDto;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 进行po和实体的转换，和event的生成等工作
 */
@Service
public class ActivityFactory {
    public ActivityDO getActivityDO(Activity activity) {

        ActivityDO activityVO = MapperFactory.getCopyByRefMapper().mapClass(Activity.class, ActivityDO.class).register()
                .map(activity, ActivityDO.class);
        return activityVO;
    }

    public Activity createActivityPO(ActivityDO vo) {
        Activity activity = MapperFactory.getCopyByRefMapper().mapClass(ActivityDO.class, Activity.class).register()
                .map(vo, Activity.class);
        return activity;
    }

    public List<ActivityDO> getActivityDOs(List<Activity> records) {

        MapperFactory.getCopyByRefMapper().mapClass(Activity.class, ActivityDO.class).register();
        List<ActivityDO> activityDOS = records.stream().map(p -> MapperFactory.getCopyByRefMapper().map(p,
                ActivityDO.class)).collect(Collectors.toList());
        return activityDOS;
    }

    public List<ActivityDto> getActivityDTOs(List<Activity> records) {
        MapperFactory.getCopyByRefMapper().mapClass(Activity.class, ActivityDto.class).register();
        List<ActivityDto> activityDOS = records.stream().map(p -> MapperFactory.getCopyByRefMapper().map(p,
                ActivityDto.class)).collect(Collectors.toList());
        return activityDOS;
    }
}
